var AjaxMethod = require("../getAjax.js"); 
var ajax = new  AjaxMethod;
export default{
    state:{
    	new_hot:'new_product', // 新品速递 热门推荐 接口参数
    	bannerList:[], 
    	newProList:[], // 新品速递
    	hotProList:[], // 热门推荐
    	indexADList:{}, //广告位
    	selectionList_one:[], // 目的地推荐
    	selectionList_two:[], // 目的地推荐
    	selectionList_three:[], // 目的地推荐
    },
    mutations:{
    	
    	set_bannerList:function(state,{list}){
    		if(list.length == 0){
    			return false;
    		}else{
				state.bannerList = list;
    		}
		},
		//新品速递
		set_newPro:function(state,{list}){
			state.newProList = list;
		},
		//热门推荐
		set_hotPro:function(state,{list}){
			state.hotProList = list;
		},
		
		//广告位
		set_indexAD:function(state,{list}){
			state.indexADList = list;
		},
		set_selection_one:function(state,{list}){
			state.selectionList_one = list;
		},
		set_selection_two:function(state,{list}){
			state.selectionList_two = list;
		},
		set_selection_three:function(state,{list}){
			state.selectionList_three = list;
		},
    },
    actions:{
    	//bannerlist
    	get_bannerList:function(context){
    		var Atype = "get", 
				Adata = {
					
				},
				Aurl = baseUrl+'/mindex/getMobileIndexBanner.html?REQUEST_JSON={visitChannel:2,pageIndex:1,CURRENCY:"CNY",commandInfo:{}}';
				//Aurl ="https://dev.singaporetong.com/api/mindex/getMobileIndexBanner.html?REQUEST_JSON={visitChannel:2,pageIndex:1,SESSION_KEY:%22%22,CURRENCY:%22CNY%22,commandInfo:{}}";
			ajax.getJson(Atype,Aurl,function(res){
				//console.log(res)
				context.commit("set_bannerList",{list:res.data.index_banner_list});
			},function(err){
				console.log(err)
			},function(){
				context.state.Ajaxing = true; // 加载中显示...
			})
    	},
    	//新品速递
    	get_newPro:function(context){
    		var Atype = "post", 
				// Adata = {
				// 	floorType:'1',
				// 	keyWord:context.state.new_hot 
				// },
				Aurl = baseUrl+"/mindex/getMobileFloorAndData.html?REQUEST_JSON={visitChannel:2,pageIndex:1,CURRENCY:'CNY',commandInfo:{floorType:1,keyWord:'new_product'}}";
			ajax.getJson(Atype,Aurl,function(res){
				console.log(res)
				//if(){}
				context.commit("set_newPro",{list:res.data.floor_list[0].datas});
			},function(err){
				console.log(err)
			},function(){
				//context.state.Ajaxing = true; // 加载中显示...
			})
    	},
    	// 热门推荐
    	get_hotPro:function(context){
    		var Atype = "get", 
				// Adata = {
				// 	floorType:'1',
				// 	keyWord:context.state.new_hot 
				// },
				Aurl = baseUrl+"/mindex/getMobileFloorAndData.html?REQUEST_JSON={visitChannel:2,pageIndex:1,CURRENCY:'CNY',commandInfo:{floorType:1,keyWord:'hot_product'}}";
			ajax.getJson(Atype,Aurl,function(res){
				console.log(res)
				//if(){}
				context.commit("set_hotPro",{list:res.data.floor_list[0].datas});
			},function(err){
				console.log(err)
			},function(){
				//context.state.Ajaxing = true; // 加载中显示...
			})
    	},
    	//广告位
    	get_indexAD:function(context){
    		var Atype = "post", 
				Aurl = baseUrl+"/mindex/getMobileFloorAndData.html?REQUEST_JSON={visitChannel:2,pageIndex:1,CURRENCY:'CNY',commandInfo:{floorType:4,keyWord:'index_ad'}}";
				// Adata = {
				// 	"floorType":'4',
				// 	"keyWord":'index_ad'
				// };
			ajax.getJson(Atype,Aurl,function(res){
				//console.log(res)
				//if(){}
				context.commit("set_indexAD",{list:res.data.floor_list[0].datas[0]});
			},function(err){
				console.log(err)
			},function(){
				//context.state.Ajaxing = true; // 加载中显示...
			})
    	},
    	//目的地推荐
    	get_selection:function(context){
    		var Atype = "post", 
				Aurl = baseUrl+"/mindex/getMobileFloorAndData.html?REQUEST_JSON={visitChannel:2,pageIndex:1,CURRENCY:'CNY',commandInfo:{floorType:1,keyWord:'target_selection'}}";
				// Adata = {
				// 	"floorType":'1',
				// 	"keyWord":'target_selection'
				// };
			ajax.getJson(Atype,Aurl,function(res){
				//console.log(res)
				context.commit("set_selection_one",{list:res.data.floor_list[0].datas});
				context.commit("set_selection_two",{list:res.data.floor_list[1].datas});
				context.commit("set_selection_three",{list:res.data.floor_list[2].datas});
			},function(err){
				console.log(err)
			},function(){
				//context.state.Ajaxing = true; // 加载中显示...
			})
    	}
    }
}